﻿using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace IISAutoDeployment
{
    /// <summary>
    /// Any non-generic deployment dependencies are maintained in this class
    /// </summary>
    /// <remarks>
    /// Should be project specific. Meant for maintaining genericism of overall tool
    /// </remarks>
    public class Dependencies
    {
        #region API

        #region Methods
        /// <summary>
        /// Copy over dependency BLB files from system directory. Overwrites by default
        /// </summary>
        /// <remarks>
        /// Set private class property for BLB source location. Default: System32
        /// </remarks>
        /// <param name="siteDir">The site dir</param>
        /// <returns>True if success; False if error</returns>
        public bool CopyBlbFiles(DirectoryInfo siteDir)
        {
            // Sanity check
            if (!_blbSource.Any())
                return false;
            var destDir = new DirectoryInfo(Path.Combine(siteDir.FullName, "bin", "DLL"));
            if (!destDir.Exists)
            {
                destDir.Create();
            }
            foreach (var fileInfo in _blbSource)
            {
                fileInfo.CopyTo(Path.Combine(destDir.FullName, fileInfo.Name), true);
            }
            return true;
        }
        #endregion

        #region Properties
        private readonly IEnumerable<FileInfo> _blbSource = new DirectoryInfo(@"C:\Windows\System32").GetFiles().Where(x => x.Name.Contains(".blb"));
        #endregion
        
        #endregion
    }
}
